package com.baichang.taoshunda.controller;

import com.baichang.framework.controller.IController;
import com.baichang.framework.controller.IPageController;
import com.baichang.framework.controller.WebBaseController;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.framework.model.Page;
import com.baichang.taoshunda.ControllerConstants;
import com.baichang.taoshunda.service.ReportTrendsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2017/8/30 0030.
 */
@Controller
@RequestMapping(ControllerConstants.REPORT)
public class ReportTrendsWController extends WebBaseController {

    @Autowired
    private ReportTrendsService reportTrendsService;

    /**
     * 跳转举报页面
     *
     * @return
     */
    @RequestMapping("/findReportIndex")
    public String findReport() {
        return "trendsReport/index";
    }

    /**
     * 查询举报的互动信息
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryReportTrends")
    public void queryReportTrends(HttpServletRequest request, HttpServletResponse response) {
        initPage(request, response, new IPageController() {
            @Override
            public Page initPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                String userName = getString(httpServletRequest, "userName", "");
                return reportTrendsService.queryReportTrends(nowPage, pageSize,userName);
            }
        });
    }

    /**
     * 删除举报信息
     *
     * @param request
     * @param response
     */
    @RequestMapping("/deleteTrendsReport")
    public void deleteTrendsReport(final HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                Integer id = getInt(request, "id", 0);
                return reportTrendsService.deleteTrendsReport(id);
            }
        });
    }
}
